package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsCategoryMapper;
import com.qf.mapper.StatMapper;
import com.qf.pojo.DtsCategory;
import com.qf.service.DtsCategoryService;
import com.qf.vo.CategorySellAmts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Service
public class DtsCategoryServiceImpl implements DtsCategoryService {

    @Autowired
    StatMapper statMapper;

    @Autowired
    DtsCategoryMapper categoryMapper;

    @Override
    public List<CategorySellAmts> getCategorySellAmts() {
        return  statMapper.getCategorySellAmts();
    }

    @Override
    public Integer findL1ByL2(Integer l2) {
        DtsCategory categoryL1 = categoryMapper.selectById(l2);
        return categoryL1.getPid();
    }

    @Override
    public List<DtsCategory> queryL1() {
        LambdaQueryWrapper<DtsCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsCategory::getPid, 0);
        wrapper.eq(DtsCategory::getDeleted, false);
        return categoryMapper.selectList(wrapper);
    }

    @Override
    public List<DtsCategory> findL2sByL1(Integer id) {
        LambdaQueryWrapper<DtsCategory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsCategory::getPid, id);
        wrapper.eq(DtsCategory::getDeleted, false);
        return categoryMapper.selectList(wrapper);
    }

    @Override
    public DtsCategory findById(Integer categoryId) {
        return categoryMapper.selectById(categoryId);
    }
}
